package com.myhome.money.base.javaio;

import java.io.*;

/**
 * 缓冲流
 */
public class BufferStream {

    public static void main(String[] args) throws IOException {
        readByBufferInputStream();
        readByBufferedReader();
    }

    public static void readByBufferInputStream() throws IOException {
        File file = new File("d:/javaio/io/test.txt");
        byte[] bys = new byte[(int) file.length()];
        InputStream input = new BufferedInputStream(new FileInputStream(file), 2 * 1024);
        int length = input.read(bys);
        String str = new String(bys);
        System.out.println("长度：" + length + "输出结果" + str);
        input.close();
    }

    public static void readByBufferedReader() throws IOException {
        File file = new File("d:/javaio/io/test.txt");
        char[] chars = new char[(int) file.length()];
        Reader reader = new BufferedReader(new FileReader(file), 1024);
        int length = reader.read(chars);
        String str = new String(chars);
        System.out.println("长度：" + length + "输出结果" + str);
        reader.close();

    }

}
